/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-09-11
 * Time: 21:45
 */
//饿汉模式
class Singleton {
    private static Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }

    //将构造方法设置为私有的，可以保证在该类之外无法再次创建该类的实例，也就保证了单例
    private Singleton(){}
}
public class Demo1 {
    Singleton instance = Singleton.getInstance();
}
